package com.recipedb.sprint.repository;

import com.recipedb.sprint.entity.LlmOutputs;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface LlmOutputsRepository extends JpaRepository<LlmOutputs, Long> {
    List<LlmOutputs> findBySessionidOrderByCreatedAtAsc(Long sessionid);
    @Modifying
    @Query(value = "INSERT INTO llm_outputs(sessionid, content, created_at) VALUES (:sessionid, :content, now())", nativeQuery = true)
    void insertOutput(@Param("sessionid") Long sessionid, @Param("content") String content);

    @Modifying
    @Query(value = "DELETE FROM llm_outputs WHERE sessionid = :sessionid", nativeQuery = true)
    void deleteBySessionid(@Param("sessionid") Long sessionid);

}